Skip to content

Conversation

@viktortnk
Copy link

Description: Fixes an IndexError: list index out of range in ChatAnthropic that occurs when using cache_control (e.g., for prompt caching) if the final message in the input sequence has an empty content list (e.g., AIMessage(content=[])).

Previously, _get_request_payload blindly accessed formatted_messages[-1]["content"][-1]. This PR updates the logic to iterate backwards through the formatted messages and attach cache_control to the first message with non-empty content, safely skipping empty blocks.

@github-actions github-actions bot added integration Related to a provider partner package integration anthropic fix labels Nov 19, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Nov 19, 2025

CodSpeed Performance Report

Merging #34025 will not alter performance

Comparing viktortnk:fix/anthropic-cache-control-index-error (c44b82c) with master (328ba36)

Summary

✅ 3 untouched
⏩ 31 skipped1

Footnotes

  1. 31 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

anthropic fix integration Related to a provider partner package integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant